﻿(function (d, e, h) {
  var f = function () { };
  f.prototype = {
    forEach: function (a, b) {
      for (var c = a.length - 1; 0 <= c; --c) b.apply(a[c], [c])
    },
    getFilePath: function () {
      var a = d.document.location.href,
        b = d.document.location.pathname;
      a = a.substring(0, a.indexOf(b));
      b = b.substring(0, b.substr(1).lastIndexOf("/") + 1);
      return a + b
    },
    getFileContent: function (a) {
      var b = 0 < navigator.userAgent.indexOf("MSIE") ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest;
      b.open("get", a, !1);
      b.send(null);
      return b.responseText
    },
    parseNode: function (a) {
      var b = e.createElement("div");
      b.innerHTML = a;
      return b.childNodes
    },
    executeScript: function (a) {
      for (var b = /<script>([\s\S]*?)<\/script>/g, c; c = b.exec(a);) eval(c[1])
    },
    getHtml: function (a) {
      a.replace(/<script>([\s\S]*?)<\/script>/g, "");
      return a
    },
    getPrevCount: function (a) {
      for (var b = /\.\.\//g, c = 0; b.exec(a);) c += 1;
      return c
    },
    getRequestUrl: function (a, b) {
      if (/http:\/\//g.test(b)) return b;
      for (var c = this.getPrevCount(b); c--;) a = a.substring(0, a.substr(1).lastIndexOf("/") + 1);
      return a + "/" + b.replace(/\.\.\//g, "")
    },
    replaceIncludeElements: function () {
      var a = this,
        b = a.getFilePath(),
        c = e.getElementsByTagName("kimImport");
      this.forEach(c, function () {
        var c = this.getAttribute("src");
        c = a.getFileContent(a.getRequestUrl(b, c));
        for (var d = this.parentNode, e = a.parseNode(a.getHtml(c)), f = e.length, g = 0; g < f; g += 1) d.insertBefore(e[0], this);
        a.executeScript(c);
        d.removeChild(this)
      })
    }
  };
  d.onload = function () {
    (new f).replaceIncludeElements()
  }
})(window, document);